﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace ZRT.RHPX.Core.Modules
{
    /// <summary>
    /// 组件
    /// </summary>
    public abstract class Module : AreaRegistration, IModule
    {
        private AreaRegistrationContext _context;

        /// <summary>
        /// 模块名称
        /// </summary>
        public abstract string ModuleName
        {
            get;
        }

        /// <summary>
        /// 模块设置
        /// </summary>
        public NameValueCollection Settings
        {
            get;
            set;
        }

        /// <summary>
        /// 注册路由配置
        /// </summary>
        public virtual void RegisterRoutes()
        {
            MapRoute(
                ModuleName + "_default",
                ModuleName + "/{controller}/{action}.html/{id}",
            new { action = "Index", id = UrlParameter.Optional }
            );
        }

        #region  区域

        public override string AreaName
        {
            get { return ModuleName; }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            this._context = context;
            RegisterRoutes();
        }

        #endregion 区域

        #region MapRoute

        protected void MapRoute(string name, string url)
        {

            _context.MapRoute(name, url);
        }
        protected void MapRoute(string name, string url, object defaults)
        {
            _context.MapRoute(name, url, defaults);

        }
        protected void MapRoute(string name, string url, string[] namespaces)
        {
            _context.MapRoute(name, url, namespaces);
        }
        protected void MapRoute(string name, string url, object defaults, object constraints)
        {
            _context.MapRoute(name, url, defaults, constraints);
        }
        protected void MapRoute(string name, string url, object defaults, string[] namespaces)
        {
            _context.MapRoute(name, url, defaults, namespaces);
        }
        protected void MapRoute(string name, string url, object defaults, object constraints, string[] namespaces)
        {
            _context.MapRoute(name, url, defaults, constraints, namespaces);
        }

        #endregion
    }
}
